package com.tz.util;

import com.tz.bean.LaterOrder;
import com.tz.bean.Shoporder;
import com.tz.dao.shoporder.IShoporderMapper;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by hfl on 2017-4-28.
 */
@Component
public class TimingOrderUtil {


    @Resource
    private IShoporderMapper shoporderMapper;


//    最近5次运行时间:
//    2017/4/29 0:10:00
//    2017/4/30 0:10:00
//    2017/5/1 0:10:00
//    2017/5/2 0:10:00
//    2017/5/3 0:10:00
    //定时确认收货
    @Scheduled(cron = "0 10 0 1/1 * ?")
    public void autosaveGood() {
        int day = 15;//延迟收货天数设置
        //商城延迟收货订单得到
        saveGood("006","003", day, "004"); //商城
        saveGood("001","001007", day, "001007"); //翻新
        saveGood("002","002009", day, "002010");  //维修
        saveGood("003","003007", day, "003008");  //检测
        saveGood("004","004010", day, "004011");  //回收
        saveGood("005","005009", day, "005010");  //换款

    }

    /**
     * 定时任务确认收货方法封装
     * @param type  订单类型
     * @param beforeStatus 原来的订单状态
     * @param day         延迟时间
     * @param afterStatus   要修改成的订单状态
     */
    public void saveGood(String type, String beforeStatus, int day ,String afterStatus){
        List<Shoporder> shoporders = shoporderMapper.getReOrderLaters(new LaterOrder(type,beforeStatus,15));
        for (Shoporder o:shoporders){
            Shoporder shoporder = new Shoporder();
            shoporder.setOrderno(o.getOrderno());
            shoporder.setShoporderstatuscode(afterStatus);
            int n = shoporderMapper.update(shoporder);
            System.out.println("改变条数==="+n);
        }
    }


}
